package think.in.java.concurrency.practise.exec7;

import java.awt.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * Created by IntelliJ IDEA.
 * User: Richard
 * Date: 6/15/11
 * Time: 10:56 PM
 * To change this template use File | Settings | File Templates.
 */
public class MainThread {
    public static void main(String[] args) throws InterruptedException {
        ShareResource shareResource = new ShareResource();
        ExecutorService executorService = Executors.newCachedThreadPool();
        for(int i =0 ; i < 10; i++){
             executorService.execute(new ThreadRunnerWithThreadLocal(i,shareResource));
        }
        TimeUnit.SECONDS.sleep(1);
        executorService.shutdown();
        //there is the test for the awaitTermination
        if(!executorService.awaitTermination(200,TimeUnit.MILLISECONDS)){

            Thread.yield();
            System.out.println("!!!!!!!!!!!!!!!!some thread is running!!!!!!!!!!!!!!!!!!!!!");
             Thread.yield();
            ReentrantLock reentrantLock = new ReentrantLock();
            reentrantLock.lock();
            ReentrantReadWriteLock.ReadLock readLock ;
        }

    }
}
